<template>
    <Upload
        ref="upload"
        :before-upload="handleBeforeUpload"
        :default-file-list="defaultList"
        :on-success="handleSuccess"
        :data="data"
        action="/api/ClientsData/UploadFile"
        :format="['zip']"
        :on-format-error="handleFormatError"
    >
        <Button icon="ios-cloud-upload-outline">上传压缩文件</Button>
    </Upload>
</template>
<script>
export default {
    name: 'FileUpload',
    props: ['data', 'check', 'defaultList'],
    data() {
        return {
            isUpload: true,
            uploadList: []
        };
    },
    methods: {
        handleFormatError() {
            this.$Notice.warning({
                title: '文件格式不正确'
            });
        },
        handleBeforeUpload() {
            const check = this.uploadList.length < this.check;
            if (!check) {
                this.$Notice.warning({
                    title: '上传数量超出限制'
                });
            }
            return check;
        },
        handleSuccess(res) {
            this.$emit('setFile', res.data[0].img);
        }
    },
    mounted() {
        this.uploadList = this.$refs.upload.fileList;
    }
};
</script>
